//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: false,
    uid:"",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
    })

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    var active = this.data.active;
    //重力加速度
    wx.onAccelerometerChange(function(res) {
      if (res.x > .7 && res.y > .7) {
        that.setData({
          active: true
        })
      }
    })
  },

  
  // openHongBao
  openHongBao: function() {
    var that = this;
    var uid = this.data.uid;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=SetShake&UID=" + uid),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        if (json.ResultData == "success") {
          wx.showModal({
            title: '提示',
            content: '恭喜，您摇到了一个红包~',
            cancelText: "知道了",
            confirmText: "去看看",
            success: function(res) {
              if (res.cancel) {
                that.setData({
                  active: false
                })
              } else {
                wx.navigateTo({
                  url: '/packageA/ticketList/ticketList',
                })
              }
            },
          })
        } else {
          wx.showModal({
            title: '提示',
            content: "抢到了一个空的红包~",
            cancelText: "取消",
            confirmText: "确定",
            success: function(res) {
              if (res.cancel) {
                that.setData({
                  active: false
                })
              } else {
                that.setData({
                  active: false
                })
              }
            },
          })
        }
      }
    })
  },
  // 
})